import Vue from "vue";
import VueRouter from "vue-router";

// import LoginIn from "../views/LoginIn.vue";

Vue.use(VueRouter);

const routes = [
  // {
  //   path: "/",
  //   name: "loginIn",
  //   component: LoginIn,
  // },
  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // },
  {
    path: "/dynamicEnvironment",
    name: "dynamicEnvironment",
    component: () =>
      import(
        /* webpackChunkName: "dynamicEnvironment" */ "../views/DynamicEnvironment/DynamicEnvironment.vue"
      ),
    meta: { isAuth: true },
  },
  {
    path: "/equipmentAccount",
    name: "equipmentAccount",
    component: () =>
      import(
        /* webpackChunkName: "equipmentAccount" */ "../views/EquipmentAccount/EquipmentAccount.vue"
      ),
    meta: { isAuth: true },
  },
  {
    path: "/loopMonitoring",
    name: "loopMonitoring",
    component: () =>
      import(
        /* webpackChunkName: "loopMonitoring" */ "../views/LoopMonitoring/LoopMonitoring.vue"
      ),
    meta: { isAuth: true },
  },
  {
    path: "/telemetryCurveQuery",
    name: "telemetryCurveQuery",
    component: () =>
      import(
        /* webpackChunkName: "telemetryCurveQuery" */ "../views/TelemetryCurveQuery/TelemetryCurveQuery.vue"
      ),
    meta: { isAuth: true },
  },
  {
    path: "/runReport",
    name: "runReport",
    component: () =>
      import(
        /* webpackChunkName: "runReport" */ "../views/RunReport/RunReport.vue"
      ),
    meta: { isAuth: true },
  },
  {
    path: "/threePhaseUnbalance",
    name: "threePhaseUnbalance",
    component: () =>
      import(
        /* webpackChunkName: "threePhaseUnbalance" */ "../views/ThreePhaseUnbalance/ThreePhaseUnbalance.vue"
      ),
    meta: { isAuth: true },
  },
  {
    path: "/historicalAlarm",
    name: "historicalAlarm",
    component: () =>
      import(
        /* webpackChunkName: "historicalAlarm" */ "../views/HistoricalAlarm/HistoricalAlarm.vue"
      ),
    meta: { isAuth: true },
  },
  {
    path: "/alarmConfiguration",
    name: "alarmConfiguration",
    component: () =>
      import(
        /* webpackChunkName: "alarmConfiguration" */ "../views/AlarmConfiguration/AlarmConfiguration.vue"
      ),
    meta: { isAuth: true },
  },
  {
    path: "/manualEntry",
    name: "manualEntry",
    component: () =>
      import(
        /* webpackChunkName: "manualEntry" */ "../views/ManualEntry/ManualEntry.vue"
      ),
    meta: { isAuth: true },
  },
  {
    path: "/networkTopology",
    name: "networkTopology",
    component: () =>
      import(
        /* webpackChunkName: "networkTopology" */ "../views/NetworkTopology/NetworkTopology.vue"
      ),
    meta: { isAuth: true },
  },
  {
    path: "/powerSupplyDistributionEquipment",
    name: "powerSupplyDistributionEquipment",
    component: () =>
      import(
        /* webpackChunkName: "powerSupplyDistributionEquipment" */ "../views/PowerSupplyDistributionEquipment/PowerSupplyDistributionEquipment.vue"
      ),
    meta: { isAuth: true },
  },
];

const router = new VueRouter({
  routes,
  mode: "hash",
});

//全局前置路由守卫————初始化的时候被调用、每次路由切换之前被调用
router.beforeEach((to, from, next) => {
  //如果路由需要跳转
  if (to.meta.isAuth) {
    //判断 如果school本地存储是qinghuadaxue的时候，可以进去
    if (!localStorage.getItem("school")) {
      next(); //放行
    } else {
      alert("抱歉，您无权限查看！");
    }
  } else {
    // 否则，放行
    next();
  }
});

export default router;
